<html>

<head>
    @include('v1.common.meta')
    <link rel="stylesheet" href="{{elixir('css/basicdata.css')}}">
</head>

<body>

<div class="yjs-grid">
    <div class="yjs-grid-box">
        <div class="layui-tab">
            @if(Auth::check())
                <div class="layui-container">
                    <!-- 功能按钮区 -->
                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <fieldset class="layui-elem-field">
                                <legend>操作功能区</legend>
                                <div class="layui-field-box">
                                    <div class="layui-row">
                                        <div class="layui-col-md2">
                                            <div class="layui-inline yjs-col-separate">
                                                <a id="showQRCode" class="layui-btn layui-btn-small"
                                                   data-type="showQRCode">
                                                    <i class="yjs-icon">&#xe61c;</i> 查看二维码
                                                </a>
                                            </div>

                                            <div class="layui-inline yjs-col-separate">
                                                <a class="layui-btn layui-btn-small"
                                                   data-type="printQRCode">
                                                    <i class="yjs-icon">&#xe61c;</i> 打印二维码
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form layui-form-pane" name="toolTextbookForm"
                                         action="javascript:;" method="POST">
                                        <div class="layui-row">
                                            <div class="layui-col-md6">
                                                <div class="layui-inline yjs-col-separate">
                                                    <div class="layui-input-inline">
                                                        <input type="text" id="searchReload" name="searchContent"
                                                               placeholder="请输入考试号关键字" class="layui-input yjs-input">
                                                    </div>
                                                    <a class="layui-btn layui-btn-small" data-type="searchData">
                                                        <i class="yjs-icon">&#xe611;</i> 查询
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </fieldset>
                        </div>
                    </div>
                    <!-- 数据显示区 -->
                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <table class="layui-table" id="dataBody" lay-filter="toolTextbookList">
                            </table>
                        </div>
                    </div>
                </div>
            @else
                <div class="layui-container">
                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <blockquote class="layui-elem-quote-error">
                                友情提示：该功能只面向已成功登录系统，并具有相应权限的用户可用。
                            </blockquote>
                        </div>
                    </div>
                </div>
            @endif
        </div>
    </div>
</div>
@include('v1.common.js')
<script type="text/html" id="groupBtn">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-mini latui-btn-normal" lay-event="sureData"><i class="yjs-icon">&#xe604;</i> 确认</a>
        <a class="layui-btn layui-btn-mini" lay-event="viewData"><i class="yjs-icon">&#xe623;</i> 查看</a>
        <a class="layui-btn layui-btn-mini layui-btn-danger" lay-event="deleteData"><i class="yjs-icon">&#xe643;</i> 删除</a>
    </div>
</script>
<script src="{{elixir('js/toolsTextbook.js')}}"></script>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
        window.onload=function (){
            $("#showQRCode").click(function(){
                QrCode();
            })
            
        }
	function QrCode(){
             window.t = setInterval(clock,1000);
        }
        function stopQrCode(){
            clearInterval(window.t);
        }
	function clock(){
            $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } });
            
            // clock方法实现每隔一秒 检测一次数据库是否更改
            $.post("https://yxapi.rocksdata.com/tools/identity/get_record_textbook_status", function(data) {
//            $.post("http://127.0.0.1:8000/tools/identity/get_record_textbook_status", function(data) {
                if(data.is_used == 0){
                    var viewUrl = '/tools/textbook/item?view=' + 'viewData' + '&code=' + data . student_code;
                    layer.open({
                        type: 2
                        , id: 1 // 只允许弹出一个
                        , title: "确认信息"
                        , area: ['500px', '400px']
                        , shade: 0
                        , maxmin: true
                        , content: viewUrl
                        , btn: ['通过', '不通过']
                        , zIndex: layer.zIndex // 当前窗体层叠顺序(layui自动维护)
                        , success: function (layero, index) { // 弹出成功回调
                            // 置顶当前窗体
                            layer.setTop(layero);
                        }
                        , yes: function (index, layero) { // 通过按钮回调
                            $.ajax({
                                type: 'GET', 
                                  url: '/tools/textbook/pass_through_data?code=' + data . student_code,    //规定连同请求发送到服务器的数据；
                                  data: data,    //映射或字符串值，规定连同请求发送到服务器的数据;
                                  dataType: 'json',
                                  success: function(data) {},      //请求成功时执行的回调函数;
                            })
                            layer.close(index);
                        }
                        , btn2: function (index, layero) { // 不通过按钮回调
                            $.ajax({
                                type: 'GET', 
                                  url: '/tools/textbook/pass_through_refuse?code=' + data . student_code,    //规定连同请求发送到服务器的数据；
                                  data: data,    //映射或字符串值，规定连同请求发送到服务器的数据;
                                  dataType: 'json',
                                  success: function(data) {},      //请求成功时执行的回调函数;
                            })
                            layer.close(index);
                        }
                        , cancel: function (index, layero) { // 关闭窗体成功回调
                            layer.close(index);
                        }
                    })
                }
            });
	}
</script>
</body>
</html>
